package com.xxgc.eow.service.impl;

import com.xxgc.eow.entity.CollectArticleSecondary;
import com.xxgc.eow.entity.Collectarticle;
import com.xxgc.eow.mapper.CollectarticleMapper;
import com.xxgc.eow.service.ICollectarticleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 收藏文章表 服务实现类
 * </p>
 *
 * @author Mr.Abel
 * @since 2023-05-24
 */
@Service
public class CollectarticleServiceImpl extends ServiceImpl<CollectarticleMapper, Collectarticle> implements ICollectarticleService {

    @Resource
    private CollectarticleMapper collectarticleMapper;

    @Override
    public List<Collectarticle> getAllCollectArticleByUserId(Integer userId) {
        return collectarticleMapper.selectAllByUserId(userId);
    }

    @Override
    public int insertCollectArticle(CollectArticleSecondary collectArticleSecondary) {
        Date date = new Date();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        collectArticleSecondary.setCreateTime(localDateTime);
        return collectarticleMapper.insertCollectArticle(collectArticleSecondary);
    }

    @Override
    public Integer getArticleById(int articleId) {
        return collectarticleMapper.getArticleById(articleId);
    }

    @Override
    public int updateArticleArtucke(int articleId, int collectNum) {
        return collectarticleMapper.updateArticleArtucke(articleId,collectNum);
    }

    @Override
    public int delArticleCollect(CollectArticleSecondary collectArticleSecondary) {
        Date date = new Date();
        Instant instant = date.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();
        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
        collectArticleSecondary.setDestroyTime(localDateTime);
        return collectarticleMapper.delArticleCollect(collectArticleSecondary);
    }

    @Override
    public CollectArticleSecondary selectTfData(CollectArticleSecondary collectArticleSecondary) {
        return collectarticleMapper.selectTfData(collectArticleSecondary);
    }
}
